from machine import PWM

"""
GeekServo 舵机
"""

class GeekServo:
    def __init__(self, pin) -> None:
        self.pin = pin
        self.freq = 50

    def write_angle(self, degree):
        v_us = (degree * 2000 // 350) + 500
        duty_cycle = (v_us * 1024) // 20000 * 64
        #print(duty_cycle)
        PWM(self.pin, freq=self.freq, duty_u16=duty_cycle)


if __name__ == "__main__":
    servo = GeekServo(0)

    import time

    servo.write_angle(0)
    time.sleep(2)
    servo.write_angle(90)
    time.sleep(2)
    servo.write_angle(180)
